home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-13 / mg2a_src.zip / TERMLIB / TGETNUM.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  3KB  |  118 lines

  1. /************************************************************************
  2.  *                                      *
  3.  *              Copyright (c) 1982, Fred Fish              *
  4.  *              All Rights Reserved                  *
  5.  *                                      *
  6.  *    This software and/or documentation is released for public          *
  7.  *    distribution for personal, non-commercial use only.          *
  8.  *    Limited rights to use, modify, and redistribute are hereby      *
  9.  *    granted for non-commercial purposes, provided that all          *
  10.  *    copyright notices remain intact and all changes are clearly     *
  11.  *    documented.  The author makes no warranty of any kind with      *
  12.  *    respect to this product and explicitly disclaims any implied    *
  13.  *    warranties of merchantability or fitness for any particular     *
  14.  *    purpose.                                  *
  15.  *                                      *
  16.  ************************************************************************
  17.  */
  18. /* Modified:
  19.  * 30-Apr-86 Mic Kaczmarczik
  20.  *       Use ctype.h macros instead of the function isdigit().
  21.  *       #define index to strchr if VAXC
  22.  */
  23.  
  24.  
  25.  
  26. /*
  27.  *  LIBRARY FUNCTION
  28.  *
  29.  *    tgetnum    extract numeric option from termcap entry
  30.  *
  31.  *  KEY WORDS
  32.  *
  33.  *    termcap
  34.  *    ce functions
  35.  *
  36.  *  SYNOPSIS
  37.  *
  38.  *    tgetnum(id)
  39.  *    char *id;
  40.  *
  41.  *  DESCRIPTION
  42.  *
  43.  *    Returns numeric value of capability <id>, or -1 if <id>
  44.  *    is not found.   Knows about octal numbers, which
  45.  *    begin with 0.
  46.  *
  47.  */
  48.  
  49. #include <stdio.h>
  50. #include <ctype.h>
  51. #ifdef          VAXC
  52. #define index strchr
  53. #endif
  54.  
  55. extern char *_tcpbuf;          /* Termcap entry buffer pointer */
  56.  
  57.  
  58.  
  59. /*
  60.  *  PSEUDO CODE
  61.  *
  62.  *    Begin tgetnum
  63.  *      Initialize pointer to the termcap entry buffer.
  64.  *      While there is a field to process
  65.  *          Skip over the field separator character.
  66.  *          If this is the entry we want then
  67.  *          If the entry is not a numeric then
  68.  *              Return failure value.
  69.  *          Else
  70.  *              Initialize value to zero.
  71.  *              If number begins with zero then
  72.  *              Set accumulation base to 8.
  73.  *              Else
  74.  *              Set accumulation base to 10.
  75.  *              End if
  76.  *              While there is a numeric character
  77.  *              Accumulate the value.
  78.  *              End while
  79.  *              Return value.
  80.  *          End if
  81.  *          End if
  82.  *      End while
  83.  *      Return failure value.
  84.  *    End tgetnum
  85.  *
  86.  */
  87.  
  88. tgetnum(id)
  89. char *id;
  90. {
  91.     int value, base;
  92.     char *bp;
  93.     extern char *index();
  94.  
  95.     bp = _tcpbuf;
  96.     while ((bp = index(bp,':')) != NULL) {
  97.       bp++;
  98.       if (*bp++ == id[0] && *bp != NULL && *bp++ == id[1]) {
  99.       if (*bp != NULL && *bp++ != '#') {
  100.           return(-1);
  101.       } else {
  102.           value = 0;
  103.           if (*bp == '0') {
  104.           base = 8;
  105.           } else {
  106.           base = 10;
  107.           }
  108.           while (isdigit(*bp)) {
  109.           value *= base;
  110.           value += (*bp++ - '0');
  111.           }
  112.           return(value);
  113.       }
  114.       }
  115.     }
  116.     return(-1);
  117. }
  118.